package com.qianfeng.libra.cowshop.app.activities;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import com.qianfeng.libra.cowshop.app.R;
import com.qianfeng.libra.cowshop.app.configuration.Constants;

public class PersonActivity extends Activity implements View.OnClickListener {
private Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_person);
        context=this;
        Intent intent=getIntent();
        SharedPreferences sp=getSharedPreferences("sp", MODE_PRIVATE);
        String name=sp.getString(Constants.USER_NAME, "");
        Boolean is_log=sp.getBoolean(Constants.IS_LOGIN,false);
        TextView textName=(TextView)findViewById(R.id.nickName);
        textName.setText(name);
        TextView back=(TextView)findViewById(R.id.back);
        TextView cancel=(TextView)findViewById(R.id.cancel);
        back.setOnClickListener(this);
        cancel.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        int id=v.getId();
        switch (id)
        {
            case  R.id.back:
                finish();
                break;
            case R.id.cancel:
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("是否要注销");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        SharedPreferences sp = getSharedPreferences("sp", MODE_PRIVATE);
                        SharedPreferences.Editor editor = sp.edit();
                        editor.putBoolean(Constants.IS_LOGIN, false);
                        editor.putString(Constants.TOKEN, null);
                        editor.putString(Constants.USER_NAME,null);
                        editor.putString(Constants.USER_ID, null);
                        editor.commit();
                        Intent intent=new Intent(context,PersonActivity.class);
                        startActivity(intent);
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();
        }
    }
}
